The academic support team needs a list of active enrolments whose recent performance has declined. Compare each student with their own earlier performance in the same course.
Agree on the Rules
- Use two periods:
earlierandrecent. Each has two equally weighted assessments. - Require at least two non-NULL scores in each period before comparing averages.
- Calculate
decline_points = earlier_avg - recent_avg. - A decline of at least 15 points means Review. Otherwise an eligible enrolment has No alert.
- Keep Insufficient data separate. A zero is a valid score; a NULL or missing record is not a zero.
Prepare Your Database
Open the supplied lab8_setup.sql from the TA folder DSAI2202/lab8/ in pgAdmin and run the complete file. Use the connection setting on the right again whenever you open a new connection.
The setup also provides performance_comparison, a saved query called a view. It will support later exercises; it is not an extra table of stored assessment results.
SET search_path TO lab8;SET search_path TO lab8;
SELECT 'students' AS table_name, COUNT(*) AS row_count
FROM students
UNION ALL SELECT 'courses', COUNT(*) FROM courses
UNION ALL SELECT 'enrolments', COUNT(*) FROM enrolments
UNION ALL SELECT 'assessment_results', COUNT(*) FROM assessment_results
UNION ALL SELECT 'support_units', COUNT(*) FROM support_units
ORDER BY table_name;SET search_path TO lab8;
SELECT e.enrolment_id, e.student_id, e.course_code,
r.result_id, r.period, r.assessment_no, r.score
FROM enrolments AS e
JOIN assessment_results AS r
ON r.enrolment_id = e.enrolment_id
WHERE e.enrolment_id IN ('E01', 'E07', 'E08', 'E09', 'E24')
ORDER BY e.enrolment_id, r.period, r.assessment_no;Check the Setup Counts
| Table | Rows | One row represents |
|---|---|---|
| students | 18 | A student profile |
| courses | 4 | A course |
| enrolments | 24 | One student's enrolment in one course |
| assessment_results | 92 | One assessment result for an enrolment and period |
| support_units | 7 | A support unit in the optional hierarchy exercise |
There are 22 active and 2 withdrawn enrolments. The final investigation needs one row per active enrolment, not one row per assessment or one row per student across all courses.
Five Cases to Trace
| Enrolment | Course | Earlier scores | Recent scores | Enough evidence? |
|---|---|---|---|---|
| E01 | SQL101 | 80, 90 | 60, 70 | Yes |
| E07 | SQL101 | 80, NULL | 50, 50 | No: only one earlier score |
| E08 | SQL101 | 80, 80 | NULL, NULL | No: no graded recent scores |
| E09 | SQL101 | No rows | 60, 60 | No: missing earlier period |
| E24 | STAT101 | 0, 0 | 0, 0 | Yes |
The inspection query returns 18 assessment rows. E09 has only two rows; its earlier assessments are absent. E08 has two recent rows, but neither has a recorded score.
Check the two eligible examples
E01: earlier average 85, recent average 65, decline 20 points → Review. E24: both averages 0, decline 0 → No alert. The three other examples require an Insufficient data label.